<?php

namespace App\Providers;

use App\Facade\AppContext;
use App\Service\SmsService;
use App\Service\System\RoleService;
use App\Service\System\UserService;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //注册标签
        Blade::if('auth', function ($action) {
            $actions = explode('@',$action);
            if(count($actions)==2){
                return AppContext::can($actions[0],$actions[1]);
            }
            return AppContext::can($action);
        });
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if(env('IS_HTTPS')){
            URL::forceScheme('https');
        }
        $this->app->singleton("SystemRole", RoleService::class);
        $this->app->singleton("Sms", SmsService::class);
        $this->app->singleton("SystemUser", UserService::class);
    }
}
